<template>
	<view class="container">
		<!-- <view class="nav" :style="'padding-top:'+barHeight+'px'">
			<image class="back" @click="back()" src="../../../static/index/back.png" mode=""></image>
			<view class="nav_name">
				我的发布
			</view>
		</view> -->

		<view class="tab">
			<u-tabs :list="list1" lineHeight="5" lineWidth='15' lineColor="#FFF" @click="click"></u-tabs>
		</view>

		<scroll-view scroll-y="true" class="scroll-box" @scrolltolower="lower()">
			<u-empty v-if="list.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png">
			</u-empty>
			<view class="list" v-for="item in list" @click="godetail(item)">
				<view class="list_left">
					<image class="list_shop" :src="oss(item.images[0])" mode="aspectFill"></image>
					<view class="list_state" v-if="item.state == 1">
						发布中
					</view>
					<view class="list_state b" v-if="item.state == 2">
						已下架
					</view>
					<view class="list_state c" v-if="item.state == 0">
						待审核
					</view>
					<view class="list_state d" v-if="item.state == -1">
						审核失败
					</view>
				</view>
				<view class="list_right">
					<view class="list_name">
						{{item.name}}
					</view>
					<view class="list_price">
						¥<text class="pri">{{item.price}}</text>
					</view>
					<view class="list_more">
						<view class="list_edit"  @click.stop="edit(item)">
							<image class="edit_img" src="https://www.stck.cc/my/upload/edit.png" mode=""></image>
							<view class="edit_name">
								编辑
							</view>
						</view>
						
						<view class="list_edit" @click.stop="top(item.id)" v-if="item.state == 1">
							<!-- <image class="edit_img" src="https://www.stck.cc/my/upload/edit.png" mode=""></image> -->
							<view class="edit_name">
								置顶
							</view>
						</view>
						
						<view class="list_up" @click.stop="up(item)" v-if="item.state == 2">
							<image class="up_img" src="https://www.stck.cc/my/upload/up.png" mode=""></image>
							<view class="up_name">
								上架
							</view>
						</view>
						<view class="list_delete" @click.stop="del(item)"
							v-if="item.state == 2 || item.state == 0 || item.state == -1">
							<image class="delete_img" src="https://www.stck.cc/my/upload/delete.png" mode=""></image>
							<view class="delete_name">
								删除
							</view>
						</view>
						<view class="list_down" @click.stop="down(item)" v-if="item.state == 1">
							<image class="down_img" src="https://www.stck.cc/my/upload/down.png" mode=""></image>
							<view class="down_name">
								下架
							</view>
						</view>
						<!-- <view class="list_refresh" v-if="item.state == 1" @click.stop="refresh(item)">
							<image class="refresh_img" src="https://www.stck.cc/my/upload/flash.png" mode=""></image>
							<view class="refresh_name">
								刷新
							</view>
						</view> -->

						<view class="list_cause" v-if="item.state == -1" @click.stop="see(item)">
							查看原因
						</view>
						
					</view>
					<view class="" style="font-size: 22rpx;padding-top: 20rpx;" v-if="item.switch == 1">
						置顶到期时间：{{item.toptime | date('yyyy-mm-dd hh:MM')}}
					</view>
				</view>
			</view>
			<u-modal :show="show" :title="title" @confirm="confirm" :content='content'></u-modal>
			<u-modal :show="showa" showCancelButton :title="titlea" @cancel="cancela" @confirm="confirma"
				:content="'需要消耗'+ contenta + '积分'"></u-modal>
		</scroll-view>
		
		<TopPopup :show1="show1" :meal="meal" @ckeck="ckeck" @padlock="show1 = false" :title="false"></TopPopup>
	</view>
	
	
	</view>
</template>

<script>
	import TopPopup from "@/components/topPopup.vue"
	export default {
		components: { TopPopup },
		data() {
			return {
				page: 1,
				finish: false,
				title: '审核失败',
				content: '',
				show: false,
				showa: false,
				titlea: '刷新商品',
				contenta: '',
				barHeight: 0,
				list1: [{
						type: 1,
						name: '发布中',
					}, {
						type: 2,
						name: '已下架',
					}, {
						type: 0,
						name: '待审核'
					},
					{
						type: -1,
						name: '审核拒绝'
					}
				],
				list: [],
				type: 1,
				id: '',
				
				meal: [],
				// id:'',
				itemid:'',
				show1:false,
				current:null,
				
				myMoney:'',
				paytype:null
			}
		},
		onLoad() {
			this.barHeight = uni.getSystemInfoSync().statusBarHeight;
			this.getlist()
			uni.$on('edit',()=>{
				console.log(111)
				this.list = []
				this.page = 1
				this.finish = false
				this.getlist()
			})
			this.getcombo()
			
			this.getMoney()
			// #ifdef MP-WEIXIN
			this.paytype = 2
			// #endif
			// #ifdef APP
			this.paytype = 1
			// #endif
		},
		methods: {
			getMoney(){
				uni.$u.http.post('/getmoney ').then(res => {
					if (res.code === 1) {
						this.myMoney = res.data
					}
				}).catch((res) => {
					
				})
			},
			
			cutitem(i,id){
			this.current = i
			this.itemid = id
		},
			getcombo() {
				uni.$u.http.post('/meallist',{
					mealtype:4
				}).then(res => {
					if (res.code == 1) {
						this.meal = res.data
					}
				}).catch((res) => {
				})
			},
			//置顶
			top(id){
				this.id = id
				this.show1 = true
			},
			ckeck(e) {
				if(!e.id) return this.toast('请选择置顶套餐')
				if(this.myMoney < e.money){
					//余额不足 微信支付
					uni.$u.http.post('/meallist', {
						type:4,
						order_id: this.id,
						id:e.id,
						paytype:this.paytype
					}).then(res => {
						console.log(res)
						if (res.code == 1) {
							let that = this
							uni.requestPayment({
								appId: res.data.pay.appId,
								nonceStr: res.data.pay.nonceStr,
								package: res.data.pay.package,
								paySign: res.data.pay.paySign,
								signType: res.data.pay.signType,
								timeStamp: res.data.pay.timeStamp,
								success: (e) => {
									that.toast(res.msg)
									that.show1 = false
									setTimeout(() => {
										uni.navigateBack()
									},500)
								},
								fail: (e) => {
									that.$u.toast('支付失败');
								}
							})
						}
					}).catch((res) => {
							
					})
				}else {
					//余额支付
					uni.$u.http.post('/meallist', {
						type:4,
						order_id: this.id,
						id:e.id,
						paytype:4
					}).then(res => {
						console.log(res)
						if (res.code == 1) {
							this.toast(res.msg)
							this.show1 = false
							setTimeout(() => {
								uni.navigateBack()
							},500)
						}
					}).catch((res) => {
							
					})
				}
				// if(!this.itemid) return this.toast('请选择置顶套餐')
				// uni.$u.http.post('/meallist', {
				// 	type:4,
				// 	order_id: this.id,
				// 	id: this.itemid
				// }).then(res => {
				// 	console.log(res)
				// 	if (res.code == 1) {
				// 		this.toast(res.msg)
				// 		this.zdshow = false
				// 		this.page = 1
				// 		this.finish = false
				// 		this.list = []
				// 		this.getlist()
				// 	}
				// }).catch((res) => {
				
				// })
			},
			// 跳转详情
			godetail(item){
				// if(item.state == 1){
				// 	uni.$u.route({
				// 		url: 'pagesA/index/index_detail',
				// 		params: {
				// 			id: item.id
				// 		}
				// 	})
				// }else if(item.state == 0){
				// 	this.toast('正在审核，请稍等')
				// }else if(item.state == 2) {
				// 	this.toast('该商品已下架')
				// }else if(item.state == -1){
				// 	this.toast('该商品审核失败，请重新上传')
				// }
			},
			up(item){
				uni.$u.http.post('/postfree ', {
					type: 'up',
					id: item.id
				}).then(res => {
					if (res.code == 1) {
						this.toast(res.msg)
						setTimeout(() => {
							this.list = []
							this.page = 1
							this.finisn = false
							this.getlist()
						}, 500)
					}
				}).catch((res) => {
				
				})
			},
			// 编辑
			edit(item) {
				// uni.$u.route({
				// 	url: 'pagesA/index/upload',
				// 	params: {
				// 		data: JSON.stringify(item),
				// 		type: 0
				// 	}
				// })
				uni.$u.route({
					url: '/pages/newissue/idleItems',
					params: {
						data: JSON.stringify(item),
						type: 0
					}
				})
			},
			// 下架
			down(item) {
				let that = this
				uni.showModal({
					title: '温馨提示',
					content: '信息下架置顶状态会消失',
					success: function(res) {
						if (res.confirm) {
							uni.$u.http.post('/postfree ', {
								type: 'lower',
								id: item.id
							}).then(res => {
								if (res.code == 1) {
									that.toast(res.msg)
									setTimeout(() => {
										that.list = []
										that.page = 1
										that.finisn = false
										that.getlist()
									}, 500)
								}
							}).catch((res) => {
							
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 删除
			del(item) {
				uni.$u.http.post('/postfree ', {
					type: 'del',
					id: item.id
				}).then(res => {
					if (res.code == 1) {
						this.toast(res.msg)
						setTimeout(() => {
							this.list = []
							this.page = 1
							this.finisn = false
							this.getlist()
						}, 500)
					}
				}).catch((res) => {

				})
			},
			// 刷新
			refresh(item) {
				this.id = item.id
				uni.$u.http.post('/refreshnum').then(res => {
					if (res.code == 1) {
						this.contenta = res.data
						this.showa = true
					}
				}).catch((res) => {
				
				})
			},
			see(item) {
				this.content = item.note
				this.show = true
			},
			click(e) {
				console.log(e)
				this.type = e.type
				this.list = []
				this.page = 1
				this.finish = false
				this.getlist()
			},
			lower() {
				this.page++
				this.getlist()
			},
			getlist() {
				if (this.finish) {
					return
				}

				uni.$u.http.post('/myfree', {
					type: this.type,
					page: this.page
				}).then(res => {
					if (res.code == 1) {

						this.list = this.list.concat(res.data)
						if (res.data.length === 0) {
							this.finish = true
						}

					}
				}).catch((res) => {

				})
			},
			// 查看失败原因
			confirm() {
				this.show = false
			},
			confirma() {
				uni.$u.http.post('/postfree', {
					type: 'refresh',
					id: this.id
				}).then(res => {
					if (res.code == 1) {
						this.toast(res.msg)
						setTimeout(() => {
							this.list = []
							this.page = 1
							this.finisn = false
							this.getlist()
						}, 500)
						this.showa = false
					}
				}).catch((res) => {
				
				})
				console.log(111)
			},
			cancela() {
				this.showa = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		height: 100vh;
		display: flex;
		flex-direction: column;
		
		/deep/ .u-tabs__wrapper__nav__item__text {
			font-size: 17px;
		}
		

		.nav {
			margin: 0 30rpx;
			padding-bottom: 30rpx;
			display: flex;
			flex-direction: row;
			align-items: center;

			.back {
				width: 40rpx;
				height: 40rpx;
			}

			.nav_name {
				flex: 1;
				margin-right: 30rpx;
				text-align: center;
				font-size: 36rpx;
				font-weight: bold;
				line-height: 40rpx;
			}
		}

		.tab {
			display: flex;
			justify-content: center;
		}

		.scroll-box {
			margin-top: 40rpx;
			flex: 1;
			overflow: hidden;

			.list {
				margin: 0 30rpx;
				margin-bottom: 50rpx;
				display: flex;
				align-items: center;
				flex-direction: row;


				.list_left {
					margin-right: 30rpx;
					position: relative;
					width: 210rpx;
					height: 210rpx;
					border-radius: 20rpx;

					.list_shop {
						width: 100%;
						height: 100%;
						border-radius: 20rpx;
					}

					.list_state {
						position: absolute;
						bottom: 0;
						width: 100%;
						height: 54rpx;
						color: #fff;
						text-align: center;
						background: rgba(0, 188, 9, 0.5);
						border-radius: 0 0 20rpx 20rpx;
					}

					.b {
						background: rgba(51, 51, 51, 0.5);
					}

					.c {
						background: rgba(254, 191, 78, 0.7);
					}

					.d {
						background: rgba(234, 0, 0, 0.5);
					}
				}

				.list_right {
					display: flex;
					flex-direction: column;

					.list_name {
						width: 440rpx;
						overflow: hidden;
						/*内容溢出隐藏*/
						text-overflow: ellipsis; //*溢出的文本显示为...*/
						display: -webkit-box;
						/*将div转换为盒子模型*/
						-webkit-line-clamp: 2;
						/*设置div的文本为2行*/
						-webkit-box-orient: vertical;
						/*从顶部向底部垂直布置子元素*/
						font-size: 28rpx;
						font-weight: normal;
						color: #323232;
						line-height: 34rpx;
					}

					.list_price {
						margin: 40rpx 0;
						font-size: 28rpx;
						font-weight: bold;
						color: #333333;
						line-height: 34rpx;
						color: #FD675C;

						.pri {
							font-size: 48rpx;
						}
					}

					.list_more {
						display: flex;
						flex-direction: row;
						justify-content: space-between;

						.list_edit {
							display: flex;
							flex-direction: row;
							align-items: center;

							.edit_img {
								margin-right: 10rpx;
								width: 30rpx;
								height: 30rpx;
							}

							.edit_name {
								font-size: 28rpx;
								font-weight: normal;
								color: #3D3D3D;
								line-height: 34rpx;
							}
						}

						.list_up {
							display: flex;
							flex-direction: row;
							align-items: center;

							.up_img {
								margin-right: 10rpx;
								width: 30rpx;
								height: 30rpx;
							}

							.up_name {
								font-size: 28rpx;
								font-weight: normal;
								color: #0256FF;
								line-height: 34rpx;
							}
						}

						.list_delete {
							display: flex;
							flex-direction: row;
							align-items: center;

							.delete_img {
								margin-right: 10rpx;
								width: 30rpx;
								height: 30rpx;
							}

							.delete_name {
								font-size: 28rpx;
								font-weight: normal;
								color: #E90000;
								line-height: 34rpx;
							}
						}

						.list_down {
							display: flex;
							flex-direction: row;
							align-items: center;

							.down_img {
								margin-right: 10rpx;
								width: 30rpx;
								height: 30rpx;
							}

							.down_name {
								font-size: 28rpx;
								font-weight: normal;
								color: #E90000;
								line-height: 34rpx;
							}
						}

						.list_refresh {
							display: flex;
							flex-direction: row;
							align-items: center;

							.refresh_img {
								margin-right: 10rpx;
								width: 30rpx;
								height: 30rpx;
							}

							.refresh_name {
								font-size: 28rpx;
								font-weight: normal;
								color: #0256FF;
								line-height: 34rpx;
							}
						}

						.list_cause {
							font-size: 28rpx;
							font-weight: normal;
							color: #333333;
							line-height: 34rpx;
						}


					}
				}
			}
		}
	}
	
	
	.serveBox {
		width: 690rpx;
		border-radius: 20rpx;
	
		.serve_tit {
			margin-top: 30rpx;
			text-align: center;
			font-size: 36rpx;
			color: #333333;
			font-weight: bold;
			line-height: 40rpx;
		}
		
		.tc-img {
			width: 600rpx;
			margin: auto;
			image {
				width: 600rpx;
				height: 500rpx;
			}
		}
		
		.serve_cont {
			// margin: 0 30rpx;
			display: flex;
			// flex-wrap: wrap;
			// flex-direction: row;
			
			margin-top: 24rpx;
			overflow: hidden;
			overflow-x: auto;
			white-space: nowrap;
	
	
			.serve {
				margin: 30rpx 0;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin-right: 20rpx;
				padding: 16rpx 32rpx;
				// width: 190rpx;
				// height: 200rpx;
				box-sizing: border-box;
				border-radius: 20rpx;
				border: 1rpx solid #989898;
	
	
				.serve_num {
					margin-bottom: 20rpx;
					font-size: 30rpx;
					font-weight: bold;
					color: #333;
					line-height: 45rpx;
				}
	
				.serve_hour {
					font-size: 28rpx;
					font-weight: 400;
					color: #323232;
					line-height: 40rpx;
				}
			}
	
			.active {
				border: 2px solid #FF7A7A !important;
			}
	
		}
		
		.tc-btn-box {
			width: 560rpx;
			margin: auto;
			margin-top: 20rpx;
			display: flex;
			justify-content: space-between;
			.tc-btn1 {
				width: 220rpx;
				height: 80rpx;
				background-color: #FBBA45;
				border-radius: 10rpx;
				text-align: center;
				line-height: 80rpx;
			}
			.tc-btn2 {
				width: 220rpx;
				height: 80rpx;
				border-radius: 10rpx;
				text-align: center;
				line-height: 80rpx;
				background-color: #9A9A9A;
				color: #FFF;
			}
		}
	
	}
</style>
